package com.bianyuanren.v4.service.version.impl;

import java.util.List;

import com.bianyuanren.v4.service.version.IPpVersionService;
import com.bianyuanren.v4.mapper.version.PpVersionMapper;
import com.bianyuanren.v4.pojo.version.PpVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bianyuanren.common.core.text.Convert;

/**
 * 边缘人版本号控制Service业务层处理
 * 
 * @author bianyuanren
 * @date 2020-03-16
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class PpVersionServiceImpl implements IPpVersionService
{
    @Autowired
    private PpVersionMapper ppVersionMapper;

    /**
     * 查询边缘人版本号控制
     * 
     * @param versionId 边缘人版本号控制ID
     * @return 边缘人版本号控制
     */
    @Override
    public PpVersion selectPpVersionById(Long versionId)
    {
        return ppVersionMapper.selectPpVersionById(versionId);
    }

    /**
     * 查询边缘人版本号控制列表
     * 
     * @param ppVersion 边缘人版本号控制
     * @return 边缘人版本号控制
     */
    @Override
    public List<PpVersion> selectPpVersionList(PpVersion ppVersion)
    {
        return ppVersionMapper.selectPpVersionList(ppVersion);
    }

    /**
     * 新增边缘人版本号控制
     * 
     * @param ppVersion 边缘人版本号控制
     * @return 结果
     */
    @Override
    public int insertPpVersion(PpVersion ppVersion)
    {
        return ppVersionMapper.insertPpVersion(ppVersion);
    }

    /**
     * 修改边缘人版本号控制
     * 
     * @param ppVersion 边缘人版本号控制
     * @return 结果
     */
    @Override
    public int updatePpVersion(PpVersion ppVersion)
    {
        return ppVersionMapper.updatePpVersion(ppVersion);
    }

    /**
     * 删除边缘人版本号控制对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePpVersionByIds(String ids)
    {
        return ppVersionMapper.deletePpVersionByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除边缘人版本号控制信息
     * 
     * @param versionId 边缘人版本号控制ID
     * @return 结果
     */
    @Override
    public int deletePpVersionById(Long versionId)
    {
        return ppVersionMapper.deletePpVersionById(versionId);
    }

    @Override
    public PpVersion selectPpVersion(String versionName, int platform) {

        //判断传来的是什么平台的数据 platform 0--安卓  1--ios
        if (platform == 0){
            PpVersion ppVersion = ppVersionMapper.selectPpVersionAndroid();
            if (!versionName.equals(ppVersion.getVersionNumber())){
                return  ppVersion;
            }
        }
        if (platform ==1){
            PpVersion ppVersion = ppVersionMapper.selectPpVersionIos();
            if (!versionName.equals(ppVersion.getVersionNumber())){
                return  ppVersion;
            }
        }
        return null;
    }
}
